Online-Academy
Look, Read, Understand, Apply

Data Structure

MenuDriven Example

import java.util.*;
class menuDri{
    public static void main(String [] aaaaaaaaaaa){
        int op;
        String str1="Tiger";
        Scanner sc = new Scanner(System.in);
        while(true){
            System.out.println("\n1. Enter String ");
            System.out.println("2. Display Entered String in Reverse ");
            System.out.println("3. Display Length of Entered String ");
            System.out.println("4. Exit ");
            System.out.println("Enter Your Choice: ");
            op = sc.nextInt();
            switch(op){
                case 1: System.out.println("Enter String: ");
                str1 = sc.next();
                break;
                case 2: System.out.println("Reverse of "+str1);
                    for(int i=str1.length()-1;i>=0;i--)
                        System.out.print(str1.charAt(i));
                break;
                case 3:System.out.println("Length of "+str1+" is "+str1.length());
                break; 
                default: 
                sc.close();
                System.exit(0);
                break;
            }
        }
    }
}